<?php
class SiteController extends CController {

	public function actionIndex() {
		if (Yii::app ()->params ['smarty']) {
			$this->Smarty ();
			exit ();
		}
		$this->render ( "login" );
	}
	public function actionLogin() {
		$passport = addslashes ( $_POST ['passport'] );
		$password = addslashes ( $_POST ['password'] );
		$_identity = new UserIdentity ( $passport, $password );
		$_identity->authenticate ();
		if ($_identity->errorCode === UserIdentity::ERROR_NONE) {
			Yii::app ()->user->login ( $_identity, 0 );
			$this->render ( "index" );
		} else {
			if ($_identity->errorCode == 1) {
				$error = "账号不存在";
			} elseif ($_identity->errorCode) {
				$error = "密码不正确";
			}
			$this->render ( "login", array (
				
				"error" => $error 
			) );
		}
	}
	
	public function Smarty() {
		$smarty = Yii::app ()->smarty;
		$smarty->assign ( "Name", "Fred Irving Johnathan Bradley Peppergill" );
		$smarty->display ( 'index.php' );
	}
	
	public function getPassport() {
		$session = new MySession ( );
		@session_start ();
		session_write_close ();
		if (isset ( $_SESSION ['passport'] ) && ! empty ( $_SESSION )) {
			return $_SESSION ['passport'];
		}
		return FALSE;
	}
	public function actionTest() {
		$admin_model = new Admin ( );
		$ret = $admin_model->findAll ();
		print_r ( $ret );
	}
}
?>